﻿using System;
using System.Collections.Generic;

using System.Text;

namespace xReplace
{
    public class Content
    {
        public const string DEFAULT_KEY = "$$MAIN";
        public const string ABSOLUTE_FILENAME = "$$ABS_FILENAME";
        public const string RELATIVE_FILENAME = "$$REL_FILENAME";
        public const string ABSOLUTE_OUTPUT_FILENAME = "$$ABS_OUTNAME";
        public const string RELATIVE_OUTPUT_FILENAME = "$$REL_OUTNAME";
        public const string DEBUG = "$$DEBUG";

        private Dictionary<string,string> Pipelines = new Dictionary<string,string>();
        private bool m_commit = true;

        public Content() 
        {
            Pipelines.Add(Content.DEFAULT_KEY, "");
        }

        /*
         * Can throw error when multiple preset labels with the same name.
         */
        public Content(KeyValuePair<string, string>[] presetLabels)
        {
            for (int i = 0; i < presetLabels.Length; i++)
            {
                this.StoreContent(presetLabels[i].Key, presetLabels[i].Value);
            }
        }


        public bool Commit
        {
            get { return m_commit; }
            set { m_commit = value; }
        }

        public string AbsoluteFilename
        {
            get { return Pipelines[Content.ABSOLUTE_FILENAME]; }
            set { Pipelines[Content.ABSOLUTE_FILENAME] = value; }
        }

        public string RelativeFilename
        {
            get { return Pipelines[Content.RELATIVE_FILENAME]; }
            set { Pipelines[Content.RELATIVE_FILENAME] = value; }
        }

        public string AbsoluteOutputFilename
        {
            get { return Pipelines[Content.ABSOLUTE_OUTPUT_FILENAME]; }
            set { Pipelines[Content.ABSOLUTE_OUTPUT_FILENAME] = value; }
        }

        public string RelativeOutputFilename
        {
            get { return Pipelines[Content.RELATIVE_OUTPUT_FILENAME]; }
            set { Pipelines[Content.RELATIVE_OUTPUT_FILENAME] = value; }
        }
        
        public string DefaultContent
        {
            get { return Pipelines[Content.DEFAULT_KEY]; }
            set { Pipelines[Content.DEFAULT_KEY] = value; }
        }

        public string LoadContent(string key)
        {
            if (!Pipelines.ContainsKey(key)) return "";
            return Pipelines[key];
        }

        public void StoreContent(string key, string value)
        {
            if (Pipelines.ContainsKey(key))
                Pipelines[key] = value;
            else
                Pipelines.Add(key,value);
        }

        public int Count
        { 
            get{return this.Pipelines.Count;}
        }

        public  Dictionary<string,string>.Enumerator GetEnumerator()
        {
            return Pipelines.GetEnumerator();
        }
    }
}
